﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.APIAPIOperateLog
{
    public partial class Edit : EditPagebase<IAPIOperateLogContract, APIOperateLog>
    {
        public IOilSalesSerialNumContract OilSalesSerialNumContract { get; set; }
        public IOilSerialNumContract OilSerialNumContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (PageMode != pagemode.Add)
                    LoadData();
            }
        }

        protected override void LoadData(APIOperateLog entity)
        {
            ed_Name.SetValue(entity.Name);
            ed_OilSalerNo.SetValue(entity.OilSalerNo);
            ed_OilPort.SetValue(entity.OilPort);
            ed_BatchNo.SetValue(entity.BatchNo);
            ed_OpreateTime.SetValue(entity.OpreateTime);
            ed_OperateType.SetValue(entity.OperateType);
            ed_OilOutPut.SetValue(entity.OilOutPut);
            ed_Before.SetValue(entity.Before);
            ed_Last.SetValue(entity.Last);
            ed_Price.SetValue(entity.Price);
            ed_Money.SetValue(entity.Money);
            ed_UpdateTime.SetValue(entity.UpdateTime);
            ed_Operater.SetValue(entity.Operater);
            ed_Token.SetValue(entity.Token);
        }

        protected override OperationResult SaveData(APIOperateLog entity)
        {
            entity.Name = ed_Name.GetValue().ToString();
            entity.OilSalerNo = ed_OilSalerNo.GetValue().ToString();
            entity.OilPort = ed_OilPort.GetValue().ToInt();
            entity.BatchNo = ed_BatchNo.GetValue().ToString();
            entity.OpreateTime = ed_OpreateTime.GetValue().ToNullableDateTime();
            if(entity.OpreateTime ==DateTime.MinValue)
                entity.OpreateTime = null;
            entity.OperateType = ed_OperateType.GetValue().ToInt();
            entity.OilOutPut = ed_OilOutPut.GetValue().ToDouble();
            entity.Before = ed_Before.GetValue().ToDouble();
            entity.Last = ed_Last.GetValue().ToDouble();
            entity.Price = ed_Price.GetValue().ToDouble();
            entity.Money = ed_Money.GetValue().ToDouble();
            entity.UpdateTime = ed_UpdateTime.GetValue().ToNullableDateTime();
            if(entity.UpdateTime ==DateTime.MinValue)
                entity.UpdateTime = null;
            entity.Operater = ed_Operater.GetValue().ToString();
            entity.Token = ed_Token.GetValue().ToString();
            return base.SaveData(entity);
    }
    }
}
